//
//  ZYLookLeaderboardCell.m
//  DistributorAB
//
//  Created by 主事丫环 on 2019/8/29.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ZYLookLeaderboardCell.h"
#import "ZYLookLeaderboardModel.h"

@implementation ZYLookLeaderboardCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

// 1. 初始化子视图
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        UILabel *numberLab = [[UILabel alloc] init];
        numberLab.frame = CGRectMake(0, 0, KWIDTH / 2.0, 46);
        numberLab.textAlignment = NSTextAlignmentCenter;
        numberLab.font = FontSize(16);
        numberLab.textColor = kColorWithHex(0x333333);
        [self.contentView addSubview:numberLab];
        self.numberLab = numberLab;
        
        UILabel *areaLab = [[UILabel alloc] init];
        areaLab.frame = CGRectMake(KWIDTH / 2.0, 0, KWIDTH / 2.0, 46);
        areaLab.textAlignment = NSTextAlignmentCenter;
        areaLab.font = FontSize(16);
        areaLab.textColor = kColorWithHex(0x333333);
        [self.contentView addSubview:areaLab];
        self.areaLab = areaLab;
        
        UIView *viewLine = [[UIView alloc] initWithFrame:CGRectMake(18, 46, KWIDTH - 36, 1)];
        viewLine.backgroundColor = kColorWithHex(0xe2e2e2);
        [self.contentView addSubview:viewLine];
    }
    
    return self;
}
- (void)setModel:(ZYLookLeaderboardModel *)model{
    _model = model;
    if (model) {
        self.numberLab.text = [self numberToString:model.rank_no];
        self.areaLab.text = model.area_name;        
    }
}
- (NSString *)numberToString:(double)number{
    if (number > 9) {
        return [NSString stringWithFormat:@"%.0f",number];
    }else{
        return [NSString stringWithFormat:@"0%.0f",number];
    }
}
@end
